package com.neu.netty;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.ByteBuffer;

/**
 * @author 杜佳辉
 * @version 1.0
 * @date 2024-12-04-10:44
 */
public class HandlerClientHello extends SimpleChannelInboundHandler<ByteBuf> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
        /*处理收到的消息*/
        System.out.println("收到服务器消息："+byteBuf.toString(io.netty.util.CharsetUtil.UTF_8));
    }

//    @Override
//    public void channelActive(ChannelHandlerContext ctx) throws Exception {
//        /*向服务器发送消息*/
//        ctx.writeAndFlush(Unpooled.copiedBuffer("hello server",io.netty.util.CharsetUtil.UTF_8));
//    }
    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        /*处理IO异常事件*/
        cause.printStackTrace();
        ctx.close();
    }
}
